package com.data.util;

import org.apache.commons.lang3.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.IntStream;


public class DateUtil {
    public static final String PATTERN_DATE_YMD = "yyyy-MM-dd";
    public static final String PATTERN_DATE_YM = "yyyy-MM";
    public static final String PATTERN_DATE_Y = "yyyy";
    private DateUtil() {}

    /**
     * 将日期类型格式化为YMD类型的日期字符串
     * @param date
     * @return
     */
    public static String formatYMD( Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat( PATTERN_DATE_YMD );
        try {
            return sdf.format(date);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 将日期类型格式化为YM类型的日期字符串
     * @param date
     * @return
     */
    public static String formatYM( Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat( PATTERN_DATE_YM );
        try {
            return sdf.format(date);
        } catch (Exception e) {
            return null;
        }
    }

    /**
     * 将日期类型格式化为YEAR类型的日期字符串
     * @param date
     * @return
     */
    public static String formatY( Date date) {
        SimpleDateFormat sdf = new SimpleDateFormat( PATTERN_DATE_Y );
        try {
            return sdf.format(date);
        } catch (Exception e) {
            return null;
        }
    }


}
